//
//  XLGUserConfig.m
//  etionCBLogic
//
//  Created by wjxfhxy on 14-11-24.
//  Copyright (c) 2014年 GuangZhouXuanWu. All rights reserved.
//

#import "XLGUserConfig.h"

NSString *const XLGUserConfigDefaultKeySavePassword = @"SavePassword";

NSString *const XLGUserConfigDefaultKeyAutoLogin = @"AutoLogin";

NSString *const XLGUserConfigDefaultKeyOfflineLogin = @"OfflineLogin";

NSString *const XLGUserConfigHistorySuccessedLogin = @"HistorySuccessLogin";

NSString *const XLGUserConfigUserAccount = @"UserAccount";

NSString *const XLGUserConfigUserNumber = @"UserNumber";

NSString *const XLGUserConfigIsFirstRun = @"IsFirstRun";

@implementation XLGUserConfig

+(NSDictionary*)readCurrentUserConfigWithKeys:(NSArray*)keys
{
    return [XLGUserConfig readUser:[XLGContext context].m_szUsernumber configWithKeys:keys];
}

+(NSDictionary*)readUser:(NSString*)userNumber configWithKeys:(NSArray*)keys
{
    if(keys.count <= 0)
        return nil;
   
    NSMutableDictionary *tmp = nil;
    
    @synchronized(@"XLGUserConfig")
    {
        NSString *path = [[[XMSFileHelper documentPath] stringByAppendingPathComponent:userNumber] stringByAppendingPathComponent:USERCFGFE];
        if([XMSFileHelper isFileExist:path])
        {
            NSDictionary *dic = [NSDictionary dictionaryWithContentsOfFile:path];
            if(dic != nil)
            {
                tmp = [[NSMutableDictionary new] autorelease_mm];
                for(NSString *s in keys)
                {
                    tmp[s] = dic[s];
                }
            }
        }
    }
    
    return tmp;
}

+(void)writeCurrentUserConfigWithDictionary:(NSDictionary*)keyValues
{
    @synchronized(@"XLGUserConfig")
    {
        NSString *path = [[XLGContext context].m_szUserpath stringByAppendingPathComponent:USERCFGFE];
        if([XMSFileHelper isFileExist:path])
        {
            NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithContentsOfFile:path];
            [dic addEntriesFromDictionary:keyValues];
            [dic writeToFile:path atomically:NO];
        }
    }
}

@end
